<?php
	###############################################################################
	###############  2016-05-30  By JianFeng Lee mysql操作类  #####################
	###############################################################################
	class DB{
		
		function __construct($host = '127.0.0.1', $port = '3306', $dbname = '', $user = '', $pwd = '', $dbcode = 'utf8', $conntype = false){
			$this->conn = @mysql_pconnect($host.":".$port,$user,$pwd);
		    $this->db = @mysql_select_db($dbname, $this->conn) or die('mysql引擎数据库连接失败');
	        @mysql_query('set names '.$dbcode.'');
		}
		
		function query($sqlstr,$type=false){
			if($type==false){
				$sql = mysql_query($sqlstr);
				$result = mysql_fetch_assoc($sql);
			}else{
				$sql = mysql_query($sqlstr);
				while($rs = mysql_fetch_array($sql,MYSQL_ASSOC)){
					$data[] = $rs;
				}
				$result = array(
					'record'=>$data,
					'number'=>mysql_num_rows($sql)
				);
			}
			return $result;
		}

		#清空数据库
		function close(){
			$this->db = null;
		}
		
		public function setfile($msg,$file=''){
			if($file==''){
				$filename = mt_rand(100,999).'.txt';
			}else{
				$filename = $file;
			}
			file_put_contents($filename,print_r($msg,true)."\r\n",FILE_APPEND);
		}
		
	    function __destruct(){
	    	$this->close();
	    }
		
	}